/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package commons.codec;

import org.apache.commons.codec.binary.Base64;

/**
 *
 * @author WangShuai
 */
public class TestBase64 {
    public static void main(String[] args) {
        //Encode
        String s = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
        s = "AAwww.baidu.com/img/sslm1_logo.gifZZ";  //Thunder下载地址加密
        String bs = new String(Base64.encodeBase64(s.getBytes(),true)); 
        //第二个参数：optionally chunking the output into 76 character blocks.  输出的结果每76个字符进行换行
        //第三个参数：urlSafe - if true this encoder will emit - and _ instead of the usual + and / characters.   转换的结果作为URL使用，保证安全性，将+和/字符进行替换
        System.out.println(bs);

        //Decode
        String s2 = "QUF3d3cuYmFpZHUuY29tL2ltZy9zc2xtMV9sb2dvLmdpZlpa";
        String bs2 = new String(Base64.decodeBase64(s2.getBytes()));
        System.out.println(bs2);
    }
}
